package com.gujiayue.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.corundumstudio.socketio.SocketConfig;
import com.corundumstudio.socketio.SocketIOServer;
@Configuration
public class SocketIOConfig {

	@Value("${socketio.host-name}")
	private String hostName;

	@Value("${socketio.port}")
	private int port;

	@Value("${socketio.boss-threads}")
	private int bossThreads;

	@Value("${socketio.worker-threads}")
	private int workerThreads;

	@Value("${socketio.allow-custom-requests}")
	private boolean allowCustomRequests;

	@Value("${socketio.upgrade-timeout}")
	private int upgradeTimeout;

	@Value("${socketio.ping-timeout}")
	private int pingTimeout;

	@Value("${socketio.ping-interval}")
	private int pingInterval;

	@Value("${socketio.max-frame-payload-length}")
	private int maxFramePayloadLength;

	@Value("${socketio.max-http-content-length}")
	private int maxHttpContentLength;

	@Value("${socketio.so-linger}")
	private int soLinger;
	/**
	 * 以下配置在上面的application.properties中已经注明
	 * 
	 * @return
	 */
	@Bean
	public SocketIOServer socketIOServer() {
		System.out.println(hostName);
		SocketConfig socketConfig = new SocketConfig();
		socketConfig.setTcpNoDelay(true);
		socketConfig.setSoLinger(soLinger);
		com.corundumstudio.socketio.Configuration config = new com.corundumstudio.socketio.Configuration();
		config.setSocketConfig(socketConfig);
		config.setHostname(hostName);
		config.setMaxFramePayloadLength(maxFramePayloadLength);
		config.setMaxHttpContentLength(maxHttpContentLength);
		config.setPort(port);
		config.setBossThreads(bossThreads);
		config.setWorkerThreads(workerThreads);
		config.setAllowCustomRequests(allowCustomRequests);
		config.setUpgradeTimeout(upgradeTimeout);
		config.setPingTimeout(pingTimeout);
		config.setPingInterval(pingInterval);
		return new SocketIOServer(config);
	}
}
